#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    bool backspaceCompare(string s, string t)
    {
        return check(s) == check(t);
    }

    string check(string& str)
    {
        string ret;
        for (auto ch : str)
        {
            if (ch != '#')
            {
                ret += ch;
            }
            else
            {
                if (ret.size()) ret.pop_back();
            }
        }
        return ret;
    }
};